package com.xy.annotaion.handler.kotlin

import org.openqa.selenium.By
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated
import org.openqa.selenium.support.ui.WebDriverWait

fun main() {
    p("spider 0")

    System.setProperty("webdriver.chrome.driver", "driver/chromedriver.exe")

//    val driver = FirefoxDriver() //error,must have firefox browser!
    val driver = ChromeDriver()

    val wait = WebDriverWait(driver, 10)
    try {
        driver.get("https://www.baidu.com")
        driver.findElement(By.name("wd")).sendKeys("hello")
        driver.findElement(By.id("su")).click();
        val firstResult = wait.until(presenceOfElementLocated(By.cssSelector("h3")))
        p(firstResult.getAttribute("textContent"))
    } catch (e: Exception) {
        e.printStackTrace()
    } finally {
        driver.quit()
    }


}